//package com.example.concurrentprogramming8016.thread.cas;
//
//
//import sun.misc.Unsafe;
//
///**
// * @author liyanhao
// * @Date 2023-01-04 1:19
// */
//public class CASTest {
//    public static void main(String[] args) throws NoSuchFieldException {
//        Entity entity = new Entity();
//        entity.setX(0);
//        Unsafe unsafe = UnsafeFactory.getUnsafe();
//        long fieldOffset = UnsafeFactory.getFieldOffset(unsafe, Entity.class, "x");
//        boolean successful;
//        //4个参数分别是：对象实例 字段的内存偏移量 字段期望值 字段新值
//        successful = unsafe.compareAndSwapObject(entity, fieldOffset, 0, 3);
//        System.out.println(successful + "\t" + entity.getX());
//        successful = unsafe.compareAndSwapObject(entity, fieldOffset, 3, 5);
//        System.out.println(successful + "\t" + entity.getX());
//        successful = unsafe.compareAndSwapObject(entity, fieldOffset, 3, 8);
//        System.out.println(successful + "\t" + entity.getX());
//
//    }
//}
//class Entity{
//    private Integer x;
//
//    public Integer getX() {
//        return x;
//    }
//
//    public void setX(Integer x) {
//        this.x = x;
//    }
//}
